<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>整合包评价</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        form {
            max-width: 400px;
            margin: auto;
        }
        label {
            display: block;
            margin-top: 10px;
        }
        input[type="text"],
        input[type="number"],
        textarea,
        select {
            width: 100%;
            padding: 8px;
            margin-top: 5px;
            box-sizing: border-box;
        }
        button {
            margin-top: 20px;
            padding: 10px 15px;
            background-color: #007BFF;
            color: white;
            border: none;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>

<form id="integrationForm">
    <label for="packageName">整合包名称（必填）:</label>
    <input type="text" id="packageName" name="packageName" required>

    <label for="rating">你的评分:</label>
    <input type="number" id="rating" name="rating" min="0" max="10" step="1">

    <label for="comment">你的评论（必填）:</label>
    <textarea id="comment" name="comment" rows="4" required></textarea>

    <label for="playerId">你的玩家ID:</label>
    <input type="text" id="playerId" name="playerId" required>

    <label for="sensitiveName">是否名称敏感（必填）:</label>
    <select id="sensitiveName" name="sensitiveName" required>
        <option value="否">否</option>
        <option value="是">是</option>
    </select>

    <button type="submit">提交</button>
</form>

<script>
    document.addEventListener("DOMContentLoaded", function() {
        const urlParams = new URLSearchParams(window.location.search);
        const titleParam = urlParams.get('title');

        if (titleParam) {
            document.getElementById('packageName').value = titleParam;
            document.getElementById('packageName').readOnly = true;
        }

        document.getElementById('integrationForm').addEventListener('submit', function(event) {
            event.preventDefault();

            const formData = new FormData(this);
            if (!formData.get('packageName')) {
                alert('无整合包名称');
                return;
            }
            const data = {
                "整合包名称（必填）": formData.get('packageName'),
                "你的评分": formData.get('rating') || null,
                "你的评论（必填）": formData.get('comment'),
                "你的玩家ID": formData.get('playerId') || "",
                "是否名称敏感（必填）": formData.get('sensitiveName')
            };

            fetch('/add', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(data)
            })
            .then(response => response.json())
            .then(result => {
                alert(result.message);
                window.location.href = '/';
            })
            .catch(error => console.error('Error:', error));
        });
    });
</script>

</body>
</html>



